package cc.rengu.redp.system.controller;

import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.RedpResponse;
import cc.rengu.redp.system.domain.HolidayInfo;
import cc.rengu.redp.system.domain.Holidays;
import cc.rengu.redp.system.service.HolidaysService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author qiujunning
 */
@Slf4j
@Validated
@RestController
@RequestMapping("holiday")
public class HolidaysController extends BaseController {

    @Autowired
    private HolidaysService holidaysService;

    @Log("取反日期性质")
    @GetMapping("update")
    public RedpResponse updateHoliday(@RequestParam String dateStr) {
        try {
            this.holidaysService.updatePubHolidays(dateStr.trim());
        } catch (Exception e) {
            String message = "修改日期性质失败";
            log.error(message, e);
            return RedpResponse.getInstance().failure().message(message);
        }
        return RedpResponse.getInstance().success().message("修改日期性质成功");
    }

    @Log("获取日期所在月份的全部日期性质")
    @GetMapping("getMonth")
    public List<HolidayInfo> getHolidaysByDate(@RequestParam String dateStr) {

        return holidaysService.getHolidaysByDate(dateStr);
    }
}